﻿using System;
using System.Collections.Generic;
using System.IO;
using Terraria.ModLoader.IO;

namespace Terraria.ModLoader.Default
{
	// Token: 0x02000309 RID: 777
	public class StartBag : ModItem
	{
		// Token: 0x170001F1 RID: 497
		// (get) Token: 0x06001D7E RID: 7550 RVA: 0x00014EFC File Offset: 0x000130FC
		public override string Texture
		{
			get
			{
				return "ModLoader/StartBag";
			}
		}

		// Token: 0x06001D7F RID: 7551 RVA: 0x00014F03 File Offset: 0x00013103
		public override void SetStaticDefaults()
		{
			base.DisplayName.SetDefault("{$tModLoader.StartBagItemName}");
			base.Tooltip.SetDefault("{$tModLoader.StartBagTooltip}\n{$CommonItemTooltip.RightClickToOpen}");
		}

		// Token: 0x06001D80 RID: 7552 RVA: 0x00014B6A File Offset: 0x00012D6A
		public override void SetDefaults()
		{
			base.item.width = 20;
			base.item.height = 20;
			base.item.rare = 1;
		}

		// Token: 0x06001D81 RID: 7553 RVA: 0x00014F25 File Offset: 0x00013125
		internal void AddItem(Item item)
		{
			this.items.Add(item);
		}

		// Token: 0x06001D82 RID: 7554 RVA: 0x00008CF7 File Offset: 0x00006EF7
		public override bool CanRightClick()
		{
			return true;
		}

		// Token: 0x06001D83 RID: 7555 RVA: 0x0043951C File Offset: 0x0043771C
		public override void RightClick(Player player)
		{
			foreach (Item item in this.items)
			{
				int number = Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, item.type, item.stack, false, (int)item.prefix, false, false);
				if (Main.netMode == 1)
				{
					NetMessage.SendData(21, -1, -1, null, number, 1f, 0f, 0f, 0, 0, 0);
				}
			}
		}

		// Token: 0x06001D84 RID: 7556 RVA: 0x00014F33 File Offset: 0x00013133
		public override TagCompound Save()
		{
			TagCompound tagCompound = new TagCompound();
			tagCompound["items"] = this.items;
			return tagCompound;
		}

		// Token: 0x06001D85 RID: 7557 RVA: 0x00014F4B File Offset: 0x0001314B
		public override void Load(TagCompound tag)
		{
			this.items = tag.Get<List<Item>>("items");
		}

		// Token: 0x06001D86 RID: 7558 RVA: 0x004395CC File Offset: 0x004377CC
		public override void LoadLegacy(BinaryReader reader)
		{
			int num = (int)reader.ReadUInt16();
			for (int i = 0; i < num; i++)
			{
				Item item = new Item();
				ItemIO.LoadLegacy(item, reader, true, false);
				this.AddItem(item);
			}
		}

		// Token: 0x04001902 RID: 6402
		private List<Item> items = new List<Item>();
	}
}
